package com.stuManSystem.dao;

import com.stuManSystem.base.BaseDao;
import java.sql.SQLException;

public class AdminDao extends BaseDao {

    private static AdminDao ad = null;
    public synchronized static AdminDao getInstance() {
        if(ad==null)
            ad = new AdminDao();
        return ad;
    }

    //什么时候调用？
    public boolean queryForLogin(String username,String password){
        boolean result=false;
        String sql="select *from admin where username=? and password=?";
        String [] param={username,password};
        rs=db.executeQuery(sql,param);
       //抛出异常快捷键ctrl+alt+t
        try {
            if (rs.next()){
                result=true;
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return result;
    }

    public boolean insertForRegister(String username,String password){
        boolean result=false;
        String sql="insert into admin(username,password) value(?,?)";
        String [] param={username,password};
        int rowCount=db.executeUpdate(sql,param);
        //抛出异常快捷键ctrl+alt+t
            if (rowCount==1){
                result=true;
            }
        return result;
    }
}
